<template>
  <div class="proOrderDetails" @click.stop="aotuTab=false">
    <div style="margin-bottom: 10px">
      <jc-button
        :btn-arr="['remove', 'reload', 'option', 'closure', 'hangPass', 'closeHang', 'pass', 'hangUp1', 'hangUp', 'sub', 'save', !list.length && 'check', 'push', 'list']"
        :disab-arr="['close', 'cancel', 'toExcel', 'using', 'freeze']"
        :fbillno="production.fbillNo"
        :list="'/proOrderList'"
        @save="save"
        @refresh="queryTPrdMoDetails"
        @submit="save(1)"
        @noSubmit="submit(2)"
        @audit="audit(1)"
        @noAudit="audit(2)"
        @del="delPublic"
        @pushDown="pushDown"
        @handleCom1="handleCom1('1')"
        @handleCom2="handleCom1('2')"
        @hangUp="hangUp(1)"
        @hangUp1="hangUp(2)"
        @hangUp2="entryHangUp(1)"
        @hangUp3="entryHangUp(2)"
        @closure="closure(1)"
        @closure1="closure(2)"
        @closeHang="closeHang(1)"
        @closeHang1="closeHang(2)"
        @hangAudit="hangAudit(1)"
        @hangAudit2="hangAudit(2)"
        @check="check('up')"
        @check1="check('down')"
      />
    </div>
    <el-tabs v-model="activeName" @tab-click="handleOther">
      <el-tab-pane :label="$t('market.info')" name="first">
        <el-form ref="purchaseRef" :model="production" label-width="100px" size="mini">
          <el-form-item :label="$t('market.documentstatus')">
            <el-tag :type="production.stateColor">{{ production.fdocumentStatus }}</el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.orderDate')">
            <el-date-picker
              v-model.trim="production.fdate"
              type="date"
              size="mini"
              value-format="yyyy-MM-dd"
              :disabled="isDisabled"
            />
          </el-form-item>
          <el-form-item :label="$t('market.mobillNo')">
            <el-input v-model.trim="production.fbillNo" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.paezText1')">
            <el-input v-model.trim="production.fpaezText" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.cust')">
            <el-input v-model.trim="production.customer" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.order')">
            <el-input v-model.trim="production.salBillNo" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.hangUp')">
            <el-tag v-if="production.fispending === 1" type="danger">{{ $t('btn.hangUp') }}</el-tag>
            <el-tag v-else>{{ $t('btn.hangUp2') }}</el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.closure')">
            <el-tag v-if="production.fendstatus === 'B'" type="danger">{{ $t('btn.settle') }}</el-tag>
            <el-tag v-else>{{ $t('market.normal') }}</el-tag>
          </el-form-item>
          <!--          <el-form-item label="生产组织">-->
          <!--            <el-input v-model.trim="production.fprdorg" disabled />-->
          <!--          </el-form-item>-->
        </el-form>
        <div style="margin-top: 10px;">
          <el-button size="mini" style="margin-bottom: 5px;" disabled @click="newHang">{{ $t('btn.newHang') }}<!--新增行--></el-button>
          <el-button size="mini" style="margin-bottom: 5px;" @click="delHang">{{ $t('btn.delHang') }}<!--删除行--></el-button>
          <el-button size="mini" @click.native="batchFill">{{ $t('btn.batchFill') }}<!--批量填充--></el-button>
        </div>
        <jc-table
          ref="table"
          :table-data="tableData"
          :table-header="tableHeard"
          :table-height="tableHeight"
          table-selection
          :get-summaries="getSummaries"
          show-summary
          @cellClick="cellClick"
          @selectionChange="handleSelectAll"
        >
          <!--  物料编码  -->
          <template v-slot:billSlot="col">
            <el-input
              v-model.trim="col.scope.row.fnumber"
              size="mini"
              :disabled="col.scope.row.entryDocumentStatus === 'B'"
              @input="getAtuo(col.scope.$index, col.scope.row.fnumber)"
            >
              <i
                slot="prefix"
                class="iconfont icon-jin-rud-ao-bo"
                @click="sonJumpMateriel(col.scope.row.fnumber)"
              />
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="handleGetMateriel(col.scope.row, col.scope.$index)"
              />
            </el-input>
            <div v-if="aotuTab && material === col.scope.$index" :class="material<7 ? 'tabPosit': 'tabPosit1'">
              <number-code :fnumber="fnumber" @material="materialData" />
            </div>
          </template>
          <!--  用料单号  -->
          <template v-slot:btnState="col">
            <el-link type="primary" @click="materialsDetail(col.scope.row)">{{ col.scope.row.userNo }}</el-link>
          </template>
          <!--  数量  -->
          <template v-slot:tagSlot="col">
            <el-input-number v-model="col.scope.row.fqty" :disabled="col.scope.row.entryDocumentStatus === 'B'" size="mini" />
          </template>
          <!--          已完工-->
          <template v-slot:orderSlot="col">
            <span
              v-if="col.scope.row.fcompleteQty > 0"
              style="color: #67c23a;"
              @click="pushDeta(col.scope.row.fentryId)"
            >{{ col.scope.row.fcompleteQty }}</span>
            <span v-else @click="pushDeta(col.scope.row.fentryId)">{{ col.scope.row.fcompleteQty }}</span>
          </template>
          <!-- 仓库-->
          <template v-slot:operaSlot="col">
            <el-input
              v-if="!isDisabled"
              v-model="col.scope.row.fstockName"
              size="mini"
              :disabled="col.scope.row.entryDocumentStatus === 'B'"
            >
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="handleWarehouse(col.scope.$index)"
              />
            </el-input>
            <span v-else>{{ col.scope.row.fstockName }}</span>
          </template>
          <!--生产车间-->
          <template v-slot:btnStates="col">
            <el-input v-model.trim="col.scope.row.fdept" :disabled="col.scope.row.entryDocumentStatus === 'B'">
              <i
                slot="suffix"
                class="el-input__icon el-icon-search"
                @click="handleWork(col.scope.$index)"
              />
            </el-input>
          </template>
          <!--领料状态-->
          <template v-slot:text3Slot="col">
            <el-tag :type="col.scope.row.pickColor">{{ col.scope.row.fpickstatus }}</el-tag>
          </template>
          <!--明细挂起状态-->
          <template v-slot:text2Slot="col">
            <el-tag v-if="col.scope.row.zfispending === 1" type="danger">{{ $t('btn.hangUp') }}</el-tag>
            <el-tag v-else>{{ $t('btn.hangUp2') }}</el-tag>
          </template>
          <!--齐套-->
          <template v-slot:text4Slot="col">
            <el-tag v-if="col.scope.row.fulls === '不齐套'" type="danger">{{ $t('market.fulls2') }}</el-tag>
            <el-tag v-else>{{ $t('market.fulls') }}</el-tag>
          </template>
          <!--结案-->
          <template v-slot:text5Slot="col">
            <el-tag v-if="col.scope.row.fendstatus === 'B'" type="danger">{{ $t('btn.settle') }}</el-tag>
            <el-tag v-else>{{ $t('market.normal') }}</el-tag>
          </template>
          <!--行状态-->
          <template v-slot:text6Slot="col">
            <el-tag v-if="col.scope.row.entryDocumentStatus === 'B'">{{ $t('market.state2') }}</el-tag>
            <el-tag v-else type="danger">{{ $t('market.state6') }}</el-tag>
          </template>
        </jc-table>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.other')" name="log">
        <jc-marker
          ref="log"
          :fnumber="production.fbillNo"
          other-height="68vh"
          :other-url-object="otherUrlObject"
        />
      </el-tab-pane>
    </el-tabs>
    <!--    物料弹窗-->
    <material v-if="isMateria" :msg="material" @material="materialData" />
    <!-- 仓库 -->
    <selectCK
      v-if="seleceVisiblit"
      :msg="msgCK"
      :fmaterial-id="stockFnumber"
      @client="selectCK"
    />
    <!--  下推单据  -->
    <el-dialog
      v-dialogDrag
      :title="$t('market.checkBill')"
      model
      :visible.sync="isdanjuDialog"
      :close-on-click-modal="false"
      width="600px"
      top="5vh"
      center
    >
      <div style="text-align: center;height: 100px;line-height: 100px">
        <el-radio-group v-model="orderLX" @change="handleOrder">
          <el-radio v-for="item in receipts" :key="item" :label="item">{{ item }}</el-radio>
        </el-radio-group>
      </div>
      <hr>
      <div v-if="orderBool" style="text-align: center;">
        {{ $t('market.rule') }}
        <el-input v-model="convert" size="mini" disabled style="width: 178px;margin-bottom: 5px;" />
        <br>
        {{ $t('market.billType') }}
        <el-select
          v-model.trim="fbillTypeId"
          size="mini"
          filterable
        >
          <el-option
            v-for="(item, index) in billTypeData"
            :key="index"
            :label="item.fname"
            :value="item.fid"
            :disabled="item.fid===185||item.fid===186"
          />
        </el-select>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="isdanjuDialog = false">{{ $t('btn.cancel') }}</el-button>
        <el-button size="mini" type="primary" @click="pushDownOrder()">{{ $t('btn.confirm') }}</el-button>
      </span>
    </el-dialog>
    <!-- 下推明细 -->
    <pushDetail
      v-if="pushVisiblit"
      :fid="pushEntryId"
      type="3"
      @client="pushVisiblit=false"
    />
    <!--  生产部门-->
    <unit v-if="unitVisabled" msg="SX_V_WORKSHOP" @unit="selUnit" />
    <upDown v-if="upDownVis" :msg="cha" :fentryid="fentryData" @client="upDownVis=false" />
  </div>
</template>

<script>
import {
  queryMoDetails,
  updateMoStatus,
  updatePrdMo,
  pushToPrdInstock,
  auditPrdMos,
  unauditPrdMos,
  submitPrdMos,
  unsubmitPrdMos,
  delPrdMos,
  pushToPrdUninstock,
  pushMoCheck,
  insertProcess,
  insertOutsource,
  pushProToPicking,
  pushProToReturnMater,
  pushProToSupplement,
  updatefispending,
  updateDetailedfispending,
  endOrder,
  unEnd,
  entryEnd,
  entryUnEnd,
  auditEntry,
  unAuditEntry
} from '@/api/production/productionList'
import { queryViewItem } from '@/api/marketManage/marketOrder'
import { toMxAmina, toPickStues } from '@/components/ToMxamineState'
import operability from '@/mixin/Operability'
import jcMarker from '@/components/marker'
import jcButton from '@/components/Button'
import pushDetail from '@/views/production/collect/components/pushDetail'
import jumpMateriel from '@/components/JumpMateriel'
export default {
  name: 'ProductionDetails',
  components: {
    unit: () => import('@/views/basic/createMateriel2/components/unit'),
    upDown: () => import('@/components/upDown'),
    material: () => import('@/views/market/marketManage/createMarkerOrder/components/material'),
    numberCode: () => import('@/components/NumberCode'),
    jcMarker,
    selectCK: () => import('@/views/production/collect/components/seleceCK'),
    jcButton,
    pushDetail
  },
  mixins: [jumpMateriel, operability],
  props: {
    msg: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default: function() {
        return []
      }
    }
  },
  data() {
    return {
      fentryData: [],
      unitVisabled: false,
      upDownVis: false,
      cha: '',
      msgCK: 2, // 转入仓库
      targerName: 'proOrderDetails',
      stockFnumber: '',
      seleceVisiblit: false, // 仓库
      pushVisiblit: false,
      pushEntryId: 0,
      orderLX: this.$t('menu.proStirageOrder'),
      // '生产入库单''生产退库单''品质检验单''生产流程单''外包工序单'
      receipts: [this.$t('menu.proStirageOrder'), this.$t('menu.proTuiStockDetail'), this.$t('menu.qualityOrder'),
        this.$t('menu.workFlowOrder'), this.$t('menu.outProcessOrder'), this.$t('menu.proPickLian'),
        this.$t('menu.proSupplTong'), this.$t('menu.supplementary')], // 生产
      fbillTypeId: 184,
      convert: this.$t('market.scbjy'),
      billTypeData: [], // 采购订单单据
      isdanjuDialog: false, // 选择单据
      activeName: 'first',
      active: 'first',
      stateColor: '', // 状态颜色
      production: {
        fid: '',
        fdate: '',
        fbillNo: '',
        salBillNo: '',
        fpaezText: '',
        customer: '',
        fdocumentStatus: ''
      },
      fnumber: '',
      isMateria: false,
      isDisabled: false,
      aotuTab: false,
      deleteData: [], // 删除用料单数据
      dialogBol: true,
      downSW: '', // 弹窗单选数据
      selData: [], // 挂起
      downData: [], // 下推数据
      tableHeight: '72vh',
      mostatusData: [],
      delFentrys: [],
      Entrys: [],
      material: 0,
      tableData: [],
      tableHeard: [
        { label: this.$t('market.fseq'), prop: 'fseq', width: '80' },
        { label: this.$t('market.userNo'), type: 'state', prop: 'userNo', width: '120px' },
        { label: this.$t('market.fmaterial'), type: 'bill', prop: 'fnumber', width: '150px' },
        { label: this.$t('shop.fname2'), prop: 'fname', width: '100' },
        { label: this.$t('market.fmodel'), prop: 'fmodel' },
        { label: this.$t('shop.fspecificaTion'), prop: 'fspecificaTion' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' },
        { label: this.$t('market.workshop'), type: 'states', prop: 'fdept', width: '140' },
        { label: this.$t('market.funit'), prop: 'funitName', width: '80' },
        { label: this.$t('market.fqty'), type: 'tag', prop: 'fqty', width: '80' },
        { label: this.$t('market.completeQty'), type: 'order', prop: 'fcompleteQty', width: '80' },
        { label: this.$t('market.readyQty'), prop: 'freadyQty', width: '80' },
        { label: this.$t('market.stock2'), type: 'operate', prop: 'fstockName', width: '120' },
        { label: this.$t('market.stockQty'), prop: 'stockQty', width: '80' },
        { label: this.$t('market.fulls'), type: 'text4', prop: 'fulls' },
        { label: this.$t('market.pickstatus'), type: 'text3', prop: 'fstatus', width: '80' },
        { label: this.$t('market.hangUp1'), prop: 'zfispending', type: 'text2', width: '80' },
        { label: this.$t('market.closure'), type: 'text5', width: '80' },
        { label: this.$t('market.hangStates'), type: 'text6', prop: 'entryDocumentStatus', width: '80' },
        { label: this.$t('market.orderState'), prop: 'fstatus', width: '80' },
        // { label: this.$t('market.planstartDate'), prop: 'fplanstartDate' },
        // { label: this.$t('market.planfinishDate'), prop: 'fplanfinishDate' },
        { label: this.$t('market.deliveryDate'), prop: 'fdeliveryDate' },
        { label: this.$t('market.proFbillno'), prop: 'fbillNo' }
        // { label: '入库组织', prop: 'fstockorg' },
        // { label: '货主', prop: 'fowner' }
      ],
      orderBool: false,
      otherUrlObject: {}
    }
  },
  watch: {
    msg() {
      this.queryTPrdMoDetails()
      this.business()
    }
  },
  created() {
    if (this.$route.params.id) {
      this.queryTPrdMoDetails()
      this.business()
    }
    this.delFentrys = []
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 265px)' : '72vh'
  },
  methods: {
    // 下推明细
    pushDeta(id) {
      this.pushVisiblit = true
      this.pushEntryId = id
    },
    handleOrder(val) {
      if (val === this.$t('menu.qualityOrder')) {
        this.convert = this.$t('market.scbjy')
        this.fbillTypeId = 184
        this.orderBool = true
        this.purpoorder1('SX_CHECKOUT')
      } else if (val === this.$t('menu.workFlowOrder')) {
        this.convert = this.$t('market.sczlc') // '生产订单至生产流程单'
        this.fbillTypeId = 245
        this.orderBool = true
        this.purpoorder1('SX_PROCESS')
      } else if (val === this.$t('menu.outProcessOrder')) {
        this.convert = this.$t('market.sczgx') // '生产订单至外包工序单'
        this.fbillTypeId = 1317
        this.orderBool = true
        this.purpoorder1('SX_OUTSOURCE')
      } else {
        this.orderBool = false
      }
    },
    // 品质检验订单单据
    async purpoorder1(ev) {
      const { data: RES } = await queryViewItem({ viewName: ev })
      this.billTypeData = RES.list
    },
    // 输入物料编码
    getAtuo(index, fnumber) {
      this.material = index
      this.aotuTab = true
      var vm = this
      clearTimeout(vm.timer) // 清除未执行的代码，重置回初始化状态
      vm.timer = setTimeout(() => {
        this.fnumber = fnumber
      }, 600)
    },
    // 保存
    save(ev) {
      this.Entrys = []
      this.tableData.forEach(res => {
        this.Entrys.push({
          fstockId: res.fstockId,
          fworkshopId: res.fworkshopId,
          fentryId: res.fentryId,
          fqty: res.fqty,
          fmaterialId: res.fmaterialId
        })
      })
      const DATA = {
        fdate: this.production.fdate,
        fid: this.production.fid,
        moBillNo: this.production.fbillNo,
        delFentrys: this.delFentrys,
        Entrys: this.Entrys
      }
      updatePrdMo(DATA).then(res => {
        if (res.code === 0) {
          ev === 1 ? this.submit(1) : this.queryTPrdMoDetails()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 业务状态
    business() {
      queryViewItem({ viewName: 'SX_V_MOSTATUS' }).then(res => {
        this.mostatusData = res.data.list
      })
    },
    // 获取数据
    async queryTPrdMoDetails() {
      const DATA = {
        fbillNo: this.$route.params.id || this.msg
      }
      const RES = await queryMoDetails(DATA)
      if (RES.code === 0) {
        this.production = toMxAmina(RES.data)
        this.otherUrlObject = RES.data // 操作日志
        this.isDisabled = this.production.fdocumentStatus === this.$t('market.state1') || this.production.fdocumentStatus === this.$t('market.state2')
        this.tableData = RES.data.details.map(item => {
          return toPickStues(item)
        })
      } else {
        this.$confirm(RES.message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
      }
    },
    // 打开物料弹窗
    handleGetMateriel(row, index) {
      this.isMateria = true
      this.material = index
    },
    // 物料数据
    materialData(item) {
      if (item.fmaterialId) {
        const items = this.tableData[this.material]
        items.fmaterialId = item.fmaterialId
        items.fnumber = item.fnumber
        items.fdescripTion = item.fdescripTion
        items.fspecificaTion = item.fspecificaTion
        items.funitId = item.funitId
        items.funitName = item.funit
        items.fmodel = item.fmodel
      }
      this.isMateria = item.isMaterialDialog
    },
    // 打开仓库弹窗
    handleWarehouse(index) {
      this.indexSelf = index
      this.stockFnumber = this.tableData[index].fnumber
      this.seleceVisiblit = true
    },
    // 获取仓库数据
    selectCK(ev) {
      if (ev.fstockId) {
        const item = this.tableData[this.indexSelf]
        item.fstockId = ev.fstockId
        item.fstockName = ev.fname
        item.stockQty = ev.sumQty
      }
      this.seleceVisiblit = false
    },
    // 生产部门
    handleWork(index) {
      this.indexSelf = index
      this.unitVisabled = true
    },
    // 获取生产车间
    selUnit(ev) {
      if (ev.fid) {
        const item = this.tableData[this.indexSelf]
        item.fdept = ev.fname
        item.fworkshopId = ev.fid
      }
      this.unitVisabled = false
    },
    // 点击用料单
    materialsDetail(ev) {
      const id = ev.userNo
      if (this.msg) {
        this.$emit('userNo', id, 0)
      } else {
        this.$router.push({ path: `/productionEdit/${id}` })
      }
    },
    // 详情
    details(ev) {
      const id = ev.userNo
      this.$router.push({ path: `/detailsPro/${id}` })
    },
    // 全选
    handleSelectAll(val) {
      this.delfnumber = val[0]?.fnumber
      this.val = val
      this.fentryData = []
      val.forEach(res => {
        this.fentryData.push(res.fentryId)
      })
    },
    // 更新生产订单明细业务状态
    tabStus(ev) {
      const DATA = {
        fentryId: ev.fentryId,
        fstatus: ev.fstatus
      }
      updateMoStatus(DATA).then(res => {
        if (res.code === 0) {
          this.queryTPrdMoDetails()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.queryTPrdMoDetails()
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 公共函数
    toExamineFun(api, ev) {
      const DATA = {
        Numbers: [this.production.fbillNo],
        EntryIds: ev === 2 ? this.fentryData : []
      }
      api(DATA).then(res => {
        if (res.code !== 0) {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
          return
        }
        this.queryTPrdMoDetails()
        this.innerHTM = ''
        res.data.forEach(res => {
          this.innerHTM += '<div>' + res + '</div>'
        })
        this.$notify.warning({
          title: '提示',
          message: this.innerHTM,
          duration: 3000, offset: 50,
          dangerouslyUseHTMLString: true
        })
      })
    },
    // 审批通过
    async audit(ev) {
      const api = ev === 1 ? auditPrdMos : unauditPrdMos
      this.toExamineFun(api)
    },
    // 提交、反提交
    async submit(ev) {
      const api = ev === 1 ? submitPrdMos : unsubmitPrdMos
      this.toExamineFun(api)
    },
    // 结案
    async closure(ev) {
      const api = ev === 1 ? endOrder : unEnd
      this.toExamineFun(api)
    },
    // 行结案
    async closeHang(ev) {
      const api = ev === 1 ? entryEnd : entryUnEnd
      this.toExamineFun(api, 2)
    },
    // 行审核
    async hangAudit(ev) {
      const api = ev === 1 ? auditEntry : unAuditEntry
      this.toExamine(api)
    },
    // 公共函数
    toExamine(api) {
      const DATA = {
        fId: this.production.fid,
        dtlIds: this.fentryData
      }
      api(DATA).then(res => {
        if (res.code === 0) {
          this.queryTPrdMoDetails()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 删除
    delPublic() {
      if (this.isDisabled) {
        this.$confirm('请先反审核后再删除', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'error'
        })
        return
      }
      this.$confirm('此操作将永久删除该订单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const DATA = { Numbers: [this.production.fbillNo] }
        delPrdMos(DATA).then(res => {
          if (res.code !== 0) {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
            return
          }
          if (this.msg) {
            this.$emit('reload')
          } else {
            // 关闭当前页面
            this.$store.dispatch('tagsView/guanbi', this.$route)
            this.$router.push({ path: '/proOrderList' })
          }
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success'
          })
        })
      })
    },
    // 新增行
    newHang() {
      const DATA = {
        userNo: '',
        fnumber: '',
        fmodel: '',
        fdept: '',
        fbillNo: '',
        fspecificaTion: '',
        fdescripTion: '',
        funitName: '',
        fqty: 0,
        fcompleteQty: 0,
        fstatus: ''
      }
      this.tableData.push(DATA)
    },
    // 删除行
    delHang() {
      this.tableData.forEach((res, index) => {
        if (res.fnumber === this.delfnumber) {
          this.delFentrys.push(res.fentryId)
          this.tableData.splice(index, 1)
          this.$refs.table.clearSelect()
        }
      })
    },
    // 点击单元格
    cellClick(row, column, cell, event) {
      this.property = column.property
      this.subscript = row.index
    },
    // 批量填充
    batchFill() {
      const item = this.tableData[this.subscript][this.property]
      this.tableData.map((res, index) => {
        if (index >= this.subscript) {
          res[this.property] = item
        }
      })
    },
    // 下推弹窗
    pushDown() {
      this.downData = []
      if (!this.val) {
        this.$message.warning('请选择数据!')
        return
      }
      this.isdanjuDialog = true
    },
    // 下推
    pushDownOrder() {
      const DATA = {
        SoucrceIds: [this.production.fid],
        EntryIds: this.fentryData
      }
      if (this.orderLX === this.$t('menu.proStirageOrder')) {
        pushToPrdInstock(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/proStirageOrder/${res.data.fid}`
            })
            this.$message({ showClose: true, message: res.message, type: 'success' })
            this.val = []
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proTuiStockDetail')) {
        pushToPrdUninstock(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/proTuiStockDetail/${res.data.fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.qualityOrder')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData,
          fbillTypeId: this.fbillTypeId
        }
        pushMoCheck(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/qualityDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.workFlowOrder')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData,
          fbillTypeId: this.fbillTypeId
        }
        insertProcess(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/workFlowDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.outProcessOrder')) {
        const DATA = {
          SoucrceIds: [this.production.fid],
          EntryIds: this.fentryData,
          fbillTypeId: this.fbillTypeId
        }
        insertOutsource(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/outProcessDetail/${res.data}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proPickLian')) { // 领料
        const DATA = {
          SoucrceIds: this.fentryData
        }
        pushProToPicking(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/productionOrder/${res.data[0].fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.proSupplTong')) { // 退料
        const DATA = {
          SoucrceIds: this.fentryData
        }
        pushProToReturnMater(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/proSuppleDetail/${res.data[0].fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      } else if (this.orderLX === this.$t('menu.supplementary')) { // 补料
        const DATA = {
          SoucrceIds: this.fentryData
        }
        pushProToSupplement(DATA).then(res => {
          if (res.code === 0) {
            this.$router.push({
              path: `/supplementaryDetail/${res.data[0].fid}`
            })
            this.isdanjuDialog = false
          } else {
            this.$confirm(res.message, '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'error'
            })
          }
        })
      }
    },
    check(ev) {
      if (this.fentryData.length === 0) return
      this.cha = ev
      this.upDownVis = true
    },
    // 挂起、反挂起
    async hangUp(ev) {
      const DATA = {
        fids: [this.production.fid],
        fispending: ev === 1 ? 1 : 0
      }
      updatefispending(DATA).then(res => {
        if (res.code === 0) {
          this.$message({ showClose: true, message: res.message, type: 'success' })
          this.handleGetUntreated()
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
        }
      })
    },
    // 明细行挂起、反挂起
    async entryHangUp(ev) {
      const DATA = {
        fids: this.fentryData,
        fispending: ev === 1 ? 1 : 0
      }
      updateDetailedfispending(DATA).then(res => {
        if (res.code === 0) {
          this.$message({ showClose: true, message: res.message, type: 'success' })
          this.handleGetUntreated()
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
        }
      })
    },
    // 套打
    handleCom1(command) {
      const id = this.production.fbillNo
      if (command === '1') {
        this.$router.push({
          path: `/proGeneralOrd1/${id}`
        })
      } else {
        this.$router.push({
          path: `/proSuccessionOrd1/${id}`
        })
      }
    },
    handleOther(tab) {
      if (tab.name === 'log') {
        this.$refs.log.otherlog()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.proOrderDetails {
  @include listBom;
  .el-tabs {
    .tabPosit {
      padding: 5px;
      box-shadow: 0 0 2px #aaa;
      position: absolute;
      top: 3.5vh;
      left: 0;
      background-color: rgba(255, 255, 255, 1);
      z-index: 99999!important;
    }
    .tabPosit1 {
      padding: 5px;
      box-shadow: 0 0 2px #aaa;
      position: absolute;
      top: -25.69vh;
      left: 0;
      background-color: rgba(255, 255, 255, 1);
      z-index: 9999;
    }
    .el-input::v-deep .el-input__inner {
      height: 30px;
      line-height: 30px;
    }
    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 35px;
        width: 275px;
        margin-bottom: 5px;

        .btnType {
          margin-right: 5px;
        }

        .el-date-editor.el-input {
          width: 100% !important;
        }

        .el-select {
          width: 100%;
        }
      }
    }
  }
}
</style>
